<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<table id="weixin_msg_dtb_table"></table>
<script type="text/javascript">
    var $=$||{};
    var $weixin_msg_dtb_table=$('#weixin_msg_dtb_table');
    $weixin_msg_dtb_table.datagrid({
        edititem:[],
        url:'data/msgdist.json',
        pagination:true,
        singleSelect:true,
        checkOnSelect:false,
        selectOnCheck:false,
        fit:true,
        columns: [[
            {field:'ck',checkbox:true},
            {
                field:'id',
                title:'分发id'
            },
            {
                field:'recid',
                title:'接受消息',
                width:400,
                formatter:function(vilue,row){
                    return row.recname;
                }
            },
            {
                field:'sendid',
                title:'消息处理器',
                width:400,
                formatter:function(value,row){
                    return row.sendname;
                },
                editor:{
                    type: 'combogrid',
                    options: {
                        required: true,
                        idField:'id',
                        textField:'retype',
                        url:'data/msgrole.json',
                        columns:[[
                            {field: 'retype', title: '返回类型',width:100},
                            {field: 'msgid', title: '消息id'},
                            {field: 'stime', title: '开始时间', width: 180},
                            {field: 'endtime', title: '结束时间', width: 180},
                            {field: 'plugin', title: '对应插件', width: 180}
                        ]]
                    }
                }
            }
        ]],
        onBeforeEdit:function(rowIndex){
            var edititem=$weixin_msg_dtb_table.datagrid('options').edititem;
            edititem.push(rowIndex);
        },
        onDblClickRow:function(rowIndex){
            $weixin_msg_dtb_table.datagrid('beginEdit',rowIndex);
        },
        toolbar:[
            {
                iconCls:'icon-save',
                text:'接受改变',
                handler:function(){
                    var edititem=$weixin_msg_dtb_table.datagrid('options').edititem;
                    var rows=$weixin_msg_dtb_table.datagrid('getRows');
                    $.each(edititem,function(i,n){
                        var ed = $weixin_msg_dtb_table.datagrid('getEditor', {index:n,field:'sendid'});
                        rows[n]['sendname'] = $(ed.target).combogrid('getText');
                        $weixin_msg_dtb_table.datagrid('endEdit', n);
                    });
                    edititem=[];
                }
            },
            {
                iconCls:'icon-save',
                text:'保存',
                handler:function(){
                    var rows=$weixin_msg_dtb_table.datagrid('getChanges');
                    console.log(rows);
                }
            }
        ]
    });
</script>
</body>
</html>